/**
 *@author   wuwg
 *@createTime   2018/03/20
 *@updateTime   2018/04/12
 *@description  upload-list  component  上传列表组件
 */
import config from '../../../../config/config.js'
// components
import Icon from '../../../basic/icon/index.vue'
import atyProgress from '../../../data/progress/index.vue'
// prefix
const prefixCls = config.prefix + '-upload'
// module
export default {
  name: 'UploadList',
  components: { Icon, atyProgress },
  props: {
    files: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data () {
    return {
      prefixCls: prefixCls
    }
  },
  methods: {
    fileCls (file) {
      return [
                `${prefixCls}-list-file`,
                {
                  [`${prefixCls}-list-file-finish`]: file.status === 'finished'
                }
      ]
    },
    handleClick (file) {
      this.$emit('on-file-click', file)
    },
    handlePreview (file) {
      this.$emit('on-file-preview', file)
    },
    handleRemove (file) {
      this.$emit('on-file-remove', file)
    },
    format (file) {
      const format = file.name.split('.').pop().toLocaleLowerCase() || ''
      let type = 'document'

      if (['gif', 'jpg', 'jpeg', 'png', 'bmp', 'webp'].indexOf(format) > -1) {
        type = 'image'
      }
      if (['mp4', 'm3u8', 'rmvb', 'avi', 'swf', '3gp', 'mkv', 'flv'].indexOf(format) > -1) {
        type = 'ios-film'
      }
      if (['mp3', 'wav', 'wma', 'ogg', 'aac', 'flac'].indexOf(format) > -1) {
        type = 'ios-musical-notes'
      }
      if (['doc', 'txt', 'docx', 'pages', 'epub', 'pdf'].indexOf(format) > -1) {
        type = 'document-text'
      }
      if (['numbers', 'csv', 'xls', 'xlsx'].indexOf(format) > -1) {
        type = 'stats-bars'
      }
      if (['keynote', 'ppt', 'pptx'].indexOf(format) > -1) {
        type = 'ios-videocam'
      }

      return type
    },
    parsePercentage (val) {
      return parseInt(val, 10)
    }
  }
}
